layui.use(['table','laydate'], function(){
    var table = layui.table
    ,layer = layui.layer;

    //初始表格
    table.render({
        elem: '#initdate'
        ,id: 'idTable'
        ,url:renderUrl
        ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
        ,toolbar: '#toolbarDemo'//默认工具栏
        ,defaultToolbar: ['filter', 'print'] //右侧默认工具栏
        ,method:'get'//请求方式
        ,page:true//开启分页
        ,limit:15//每页记录数
        ,limits:[15,30,40,50,60,70,80,90,100]//每页记录数
        ,cols: [clos]
    });
    //监听单元格编辑
    table.on('edit(datatable)', function(obj){
        var data = obj.data //得到所在行所有键值
        //提交编辑
        $.post(editUrl,{'uid':data.id, 'mark_up':data.mark_up},function(msg){

            if(msg == 'success')
            {
                layer.msg('修改成功');      
            }else{
                layer.msg(msg);
            }
        })

    });
    //监听头工具栏事件
    table.on('toolbar(datatable)', function(obj){
        var checkStatus = table.checkStatus(obj.config.id);
        switch(obj.event)
        {
            case 'add':
                layer.open({
                    type: 2, 
                    title: '添加',
                    area: ['800px', '600px'],
                    content: addUrl
                });
                break;
            default:
                return false;
                break;
        }
    })
})
function onoffUser(id,sta)
{
    layer.load(2);
    $.post(onoffUrl,{'uid':id,'state':sta},function(msg){
        if(msg){
            layer.msg('操作成功',{time:1000},function(){location.reload(); });
        }else{
            layer.msg('操作失败');  
        }
        
    })
}
